home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
PowerMacOberon 1.2
/
Dialogs
/
DialogUtils.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1995-06-30
|
5KB
|
118 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
StampElems
Alloc
28 Nov 94
Syntax10b.Scn.Fnt
MODULE DialogUtils;
(** Markus Knasmueller 18.Nov.94 -
IMPORT DialogButtons, DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, MenuViewers, Oberon,
TextFrames, Texts, Viewers;
CONST
menu = "System.Close System.Copy System.Grow";
VAR
msgbox*, prompt* : Dialogs.Panel; (** predefined dialogs *)
left, right, top, bot: INTEGER;
PROCEDURE Min (x, y: INTEGER): INTEGER;
BEGIN IF x < y THEN RETURN x ELSE RETURN y END
END Min;
PROCEDURE Init;
VAR s: DialogStaticTexts.Item; b: DialogButtons.Item; t: DialogTexts.Item;
BEGIN
(* --- init of prompt *)
NEW (prompt);
NEW (s); s.Init; s.SetDim (18, - 36, 200, 20, FALSE); s.SetName ("s");
s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
prompt.Insert (s, FALSE);
NEW (t); t.Init; t.SetDim (25, - 70, 100, 25, FALSE); t.SetName ("t");
prompt.Insert (t, FALSE);
NEW (b); b.Init; b.SetDim (165, - 70, 40, 25, FALSE); b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
b.SetName ("OK");
prompt.Insert (b, FALSE);
(* --- init of msgbox *)
NEW (msgbox);
NEW (s); s.Init; s.SetDim (18, -36, 200, 20, FALSE);
s.SetName ("s"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
msgbox.Insert (s, FALSE);
NEW (b); b.Init; b.SetDim (18, - 70, 40, 25, FALSE); b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
b.SetName ("OK");
msgbox.Insert (b, FALSE);
END Init;
PROCEDURE box (obj: Dialogs.Object; VAR done: BOOLEAN);
VAR x, y, w, h: INTEGER;
BEGIN
obj.GetDim (x, y, w, h);
IF x < left THEN left := x END;
IF y < bot THEN bot := y END;
IF x + w > right THEN right := x + w END;
IF y + h > top THEN top := y + h END
END box;
PROCEDURE Open* (p: Dialogs.Panel; x, y: INTEGER);
(** opens a viewer at x, y showing panel p. If it is possible the whole panel will be displayed *)
VAR df: DialogFrames.Frame; v, vmax: Viewers.Viewer; h, res: INTEGER; m: TextFrames.Frame;
t: Texts.Text; buf: Texts.Buffer;
BEGIN
NEW (df); df.Open (DialogFrames.Handle, p);
v := Viewers.This (x, 0); vmax := NIL; h := 0;
WHILE v.state > 1 DO
IF v.H > h THEN vmax := v; h := v.H END;
v := Viewers.Next(v)
END;
IF vmax # NIL THEN
left := MAX (INTEGER); right := MIN(INTEGER); bot := MAX(INTEGER); top := MIN(INTEGER);
p.Enumerate (box);
y := Min(vmax.Y + ABS(bot) + 10 + TextFrames.menuH, vmax.Y + vmax.H - TextFrames.menuH - 2)
END;
IF Files.Old ("Dialog.Menu.Text") = NIL THEN
m := TextFrames.NewMenu ("Msgbox.Dlg", menu)
ELSE
m := TextFrames.NewMenu ("MsgBox.Dlg", "");
NEW (t); Texts.Open (t, "Dialog.Menu.Text");
NEW (buf); Texts.OpenBuf (buf); Texts.Save (t, 0, t.len, buf); Texts.Append (m.text, buf)
END;
v := MenuViewers.New (m, df, TextFrames.menuH, x, y);
IF p.cmd[0] # 0X THEN
Dialogs.cmdPanel := p; Oberon.Call (p.cmd, Oberon.Par, FALSE, res)
END
END Open;
PROCEDURE Align1 (p: Dialogs.Panel; msg: ARRAY OF CHAR; VAR w: INTEGER);
VAR o: Dialogs.Object; s: DialogStaticTexts.Item; cx, cy, cw, ch, i, dx: INTEGER; pat: Display.Pattern;
BEGIN
o := p.NamedObject ("s"); s := o(DialogStaticTexts.Item); s.SetString (msg);
i := 0; w := 0;
WHILE (s.s[i] # 0X) DO
Display.GetChar (s.fnt.raster, s.s[i], dx, cx, cy, cw, ch, pat);
INC (w, dx); INC (i)
END;
INC (w, dx);
s.GetDim (cx, cy, cw, ch); s.SetDim (cx, cy, w, ch, FALSE);
END Align1;
PROCEDURE AlignMsgBox (p: Dialogs.Panel; msg, cmd: ARRAY OF CHAR);
VAR o: Dialogs.Object; b: DialogButtons.Item; w, cx, cy, cw, ch: INTEGER;
BEGIN
Align1 (p, msg, w);
o := p.NamedObject ("OK"); b := o(DialogButtons.Item); b.SetCmd (cmd);
b.GetDim (cx, cy, cw, ch); cx := cx + ABS (w - cw) DIV 2;
b.SetDim (cx, cy, cw, ch, FALSE);
END AlignMsgBox;
PROCEDURE AlignPanel (p: Dialogs.Panel; msg, cmd: ARRAY OF CHAR);
VAR o: Dialogs.Object; b: DialogButtons.Item; w: INTEGER;
BEGIN
Align1 (p, msg, w);
o := p. NamedObject ("OK"); b := o(DialogButtons.Item); b.SetCmd (cmd);
END AlignPanel;
PROCEDURE MessageBox* (x, y: INTEGER; msg, cmd: ARRAY OF CHAR);
(** creates and displays a panel at x, y that contains message msg, and a pushbutton connected with cmd *)
VAR p: Dialogs.Panel;
BEGIN
p := msgbox.Copy (); AlignMsgBox (p, msg, cmd); Open (p, x, y);
END MessageBox;
PROCEDURE Prompt* (x, y: INTEGER; msg, cmd: ARRAY OF CHAR);
(** creates and displays a panel at x, y that contains message msg, and a pushbutton connected with cmd and a text item named "t" *)
VAR p: Dialogs.Panel;
BEGIN
p := prompt.Copy (); AlignPanel (p, msg, cmd); Open (p, x, y);
END Prompt;
BEGIN Init
END DialogUtils.